package org.dzq.designmode.flyweight;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: FlyweightFactory
 * @Package: org.dzq.designmode.flyweight
 * @author: 越
 * @date: 2023/6/18 21:26
 * @Description: 享元工厂：负责管理享元对象池和创建享元对象
 * 内部状态指对象共享出来的信息，存储在享元对象内部且不会随环境的改变而改变
 * 外部状态指对象得以依赖的一个标记，是随环境改变而改变的、不可共享的状态。
 */
public class FlyweightFactory {

    private static Map<String,IFlyweight> pool = new ConcurrentHashMap<>();

    public static IFlyweight getFlyweightByName(String name){
        if(!pool.containsKey(name)){
            pool.put(name,new ConcreteFlyweight(name));
        }
        return pool.get(name);
    }
}
